﻿@model Inspinia_MVC5.Models.Ebook

@{
    ViewBag.Title = "录入电子书";
}

<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-sm-4">
        <h2>录入电子书</h2>
        <ol class="breadcrumb">
            <li>
                @Html.ActionLink("列表", "Index")
            </li>
            <li class="active">
                <strong>录入电子书</strong>
            </li>
        </ol>
    </div>
    <div class="col-sm-8">
        <div class="title-action">
            @Html.ActionLink("返回列表", "Index", null, new { @class = "btn btn-primary" })
        </div>
    </div>
</div>



<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>录入电子书</h5>
                </div>
                <div class="ibox-content">

                    @using (Html.BeginForm("Create","Ebooks",FormMethod.Post,new {enctype="multipart/form-data" }))
                    {
                        @Html.AntiForgeryToken()

                    <div class="form-horizontal">
                        @Html.ValidationSummary(true)

                        <div class="form-group">
                            @Html.LabelFor(model => model.EbookName, new { @class = "control-label col-md-2" })
                            <div class="col-md-10">
                                @Html.EditorFor(model => model.EbookName)
                                @Html.ValidationMessageFor(model => model.EbookName)
                            </div>
                        </div>

                        <div class="form-group">
                            @Html.LabelFor(model => model.EbookISBN, new { @class = "control-label col-md-2" })
                            <div class="col-md-10">
                                @Html.EditorFor(model => model.EbookISBN)
                                @Html.ValidationMessageFor(model => model.EbookISBN)
                            </div>
                        </div>

                        @*<div class="form-group">
            @Html.LabelFor(model => model.EbookPic, new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.EbookPic)
                @Html.ValidationMessageFor(model => model.EbookPic)
            </div>
        </div>*@

                        <div class="form-group">
                            @Html.LabelFor(model => model.EbookAuthor, new { @class = "control-label col-md-2" })
                            <div class="col-md-10">
                                @Html.EditorFor(model => model.EbookAuthor)
                                @Html.ValidationMessageFor(model => model.EbookAuthor)
                            </div>
                        </div>

                        <div class="form-group">
                            @Html.LabelFor(model => model.EbookPress, new { @class = "control-label col-md-2" })
                            <div class="col-md-10">
                                @Html.EditorFor(model => model.EbookPress)
                                @Html.ValidationMessageFor(model => model.EbookPress)
                            </div>
                        </div>



                        <div class="form-group">
                            @Html.LabelFor(model => model.Status, new { @class = "control-label col-md-2" })
                            <div class="col-md-10">
                                @Html.EditorFor(model => model.Status)
                                @Html.ValidationMessageFor(model => model.Status)
                            </div>
                        </div>

                        <div class="form-group">
                            @Html.Label("所属类别", new { @class = "control-label col-md-2" })
                            <div class="col-md-10">
                                @Html.DropDownList(name: "BookTypeId", selectList: null, optionLabel: String.Empty, htmlAttributes: new { @class = "form-control m-b" })

                                @Html.ValidationMessageFor(model => model.BookTypeId)
                            </div>
                        </div>
                        <div class="form-group">
                            @Html.LabelFor(model => model.Desc, new { @class = "control-label col-md-2" })
                            <div class="col-md-10">
                                @Html.TextAreaFor(model => model.Desc, new { rows = 10, cols = 95 });
                                @*@Html.EditorFor(@*)*@
                                @Html.ValidationMessageFor(model => model.Desc)
                            </div>
                        </div>
                        <div class="form-group">
                            @Html.LabelFor(model => model.EbookPic, new { @class = "control-label col-md-2" })
                            <div class="col-md-10">
                                <div class="fileupload-box">
                                    <p>上传图片:</p>
                                    <div class="img-box">
                                        <input type="file" style="display:none" name="photo" id="uploadfile" accept="image/*" />
                                        <img src="~/Content/Images/addpic.png" id="image">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            @*<div class="col-md-2">
                上传PDF
            </div>*@
                            @Html.Label("上传PDF", new { @class = "control-label col-md-2" })

                            <div class="col-md-10">
                                <div class="fileinput fileinput-new input-group" data-provides="fileinput">
                                    <div class="form-control" data-trigger="fileinput"><i class="glyphicon glyphicon-file fileinput-exists"></i> <span class="fileinput-filename"></span></div>
                                    <span class="input-group-addon btn btn-default btn-file"><span class="fileinput-new">选择文件</span><span class="fileinput-exists">更改</span><input type="file" name="pdf"></span>
                                    <a href="#" class="input-group-addon btn btn-default fileinput-exists" data-dismiss="fileinput">删除</a>
                                </div>

                            </div>
                        </div>
                        @*<div class="form-group">
            @Html.LabelFor(model => model.YueDuLiang, new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.YueDuLiang)
                @Html.ValidationMessageFor(model => model.YueDuLiang)
            </div>
        </div>*@

                        <div class="form-group">
                            <div class="col-md-offset-2 col-md-10">
                                <input type="submit" value="保存" class="btn btn-primary" />
                                @Html.ActionLink("取消", "Index", null, new { @class = "btn btn-white" })
                            </div>
                        </div>
                    </div>
                    }

                </div>
            </div>
        </div>
    </div>
</div>



@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
    @Scripts.Render("~/plugins/dropZone")
    @Scripts.Render("~/plugins/jasnyBootstrap")
    @Scripts.Render("~/plugins/codeEditor")

    <script type="text/javascript">
        $(function () {
            $("#image").click(function () {
                $("#uploadfile").click();
            })
            $("#uploadfile").change(function () {

                var files = $(this)[0].files[0];    //获取文件信息
                if (files) {
                    var reader = new FileReader();  //调用FileReader
                    reader.onload = function (evt) {   //读取操作完成时触发。
                        $("#image").attr('src', evt.target.result)  //将img标签的src绑定为DataURL
                    }
                    reader.readAsDataURL(files); //将文件读取为 DataURL(base64)
                }
                else {
                    alert("上传失败");
                }
            })
        })
    </script>

    <script type="text/javascript">
        Dropzone.options.dropzoneForm = {
            paramName: "file", // The name that will be used to transfer the file
            maxFilesize: 2, // MB
            dictDefaultMessage: "<strong>Drop files here or click to upload. </strong></br> (This is just a demo dropzone. Selected files are not actually uploaded.)"
        };

        $(document).ready(function () {

            var editor_one = CodeMirror.fromTextArea(document.getElementById("code1"), {
                lineNumbers: true,
                matchBrackets: true
            });

            var editor_two = CodeMirror.fromTextArea(document.getElementById("code2"), {
                lineNumbers: true,
                matchBrackets: true
            });

            var editor_two = CodeMirror.fromTextArea(document.getElementById("code3"), {
                lineNumbers: true,
                matchBrackets: true
            });

        });
    </script>
}
@section Styles{
    @Styles.Render("~/Content/plugins/dropzone/dropZoneStyles")
    @Styles.Render("~/plugins/jasnyBootstrapStyles")
    @Styles.Render("~/plugins/codeEditorStyles")

    <style>
        .fileupload-box {
            padding: 5px;
            border: 2px dashed gainsboro;
            height: 180px;
            width: 400px;
            position: relative
        }

            .fileupload-box p {
                margin: 5px 0 0 5px;
            }

        .img-box {
            position: absolute;
            width: 120px;
            height: 120px;
            left: 0;
            right: 0;
            top: 10px;
            bottom: 0;
            margin: auto;
        }

            .img-box img {
                width: 120px;
                height: 120px;
            }
    </style>
}
